package main

import (
	"go-gin-example/pkg/setting"
	"log/slog"
	"os"
	"time"

	"github.com/robfig/cron"
	"go-gin-example/models"
)

var (
	log = slog.New(slog.NewJSONHandler(os.Stdout, nil))
)

func main() {
	setting.Setup()
	models.Setup()
	log.Info("cron Starting...")

	c := cron.New()
	_ = c.AddFunc("5 * * * * *", func() {
		log.Info("Run models.CleanAllTag...")
		if ok, err := models.CleanAllTag(); !ok {
			log.Error("删除标签出现错误: %v", err)
		}
	})
	_ = c.AddFunc("5 * * * * *", func() {
		log.Error("Run models.CleanAllArticle...")
		if ok, err := models.CleanAllArticle(); !ok {
			log.Error("删除文章出现错误: %v", err)
		}
	})
	c.Start()

	t1 := time.NewTimer(time.Second * 10)
	for {
		select {
		case <-t1.C:
			t1.Reset(time.Second * 10)
		}
	}
}
